package com.hot100.easy;

/**
 * @ClassName Demo21
 * @Description 汉明距离
 * @Author zt
 * @Date 17:09 2022/6/12
 * @Version 1.0
 **/
public class Demo21 {
    public static void main(String[] args) {
        hammingDistance(1,4);
    }

    public static int hammingDistance(int x, int y) {
        String i = Integer.toBinaryString(x);
        String j = Integer.toBinaryString(y);
        int count=0;
        while (j.length()!=i.length()){
            if(j.length()<i.length()){
                j='0'+j;
            }else {
                i='0'+i;
            }
        }
        for (int k = 0; k <j.length() ; k++) {
            if(i.charAt(k)!=j.charAt(k)){
                count++;
            }
        }

        return count;
    }
}